package hanxx.security.dao;

import hanxx.security.domain.SysRoleDept;
import hanxx.system.dao.BaseDao;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.io.Serializable;

/**
 * 角色与部门关联表 数据层
 *
 */
public interface SysRoleDeptDao extends BaseDao<SysRoleDept, Serializable>
{
    /**
     * 通过角色ID删除角色和部门关联
     * 
     * @param roleId 角色ID
     * @return 结果
     */
    @Modifying
    @Query(nativeQuery = true,value = "delete from sys_role_dept where role_id=?1")
    public int deleteRoleDeptByRoleId(Long roleId);

    /**
     * 批量删除角色部门关联信息
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Modifying
    @Query(nativeQuery = true,value = "delete from sys_role_dept where role_id in (?1)")
    public int deleteRoleDept(Long[] ids);

    /**
     * 查询部门使用数量
     * 
     * @param deptId 部门ID
     * @return 结果
     */
    @Query(value = "select count(1) from sys_role_dept where dept_id=?1 ",nativeQuery =true )
    public int selectCountRoleDeptByDeptId(Long deptId);


}
